package inseniarlingua.trans.en_ia;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

class TranslatorTest 
{
	Translator cut

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		cut = new Translator()
	}

	@After
	public void tearDown() throws Exception {
	}
	
	private void assertTransMap(Map transMap) {
		transMap.each { exp, en ->
			assertEquals(exp, cut.translate(en))
		}
	}

	@Test
	public void testTranslate() {
		assertEquals('martedi', cut.translate('Tuesday'))
		assertEquals('le', cut.translate('the'))
		assertEquals('esseva', cut.translate('was'))
		assertEquals('esser', cut.translate('to be'))
		assertEquals('lacte', cut.translate('milk'))
	}
	
	@Test
	public void testTranslateMulti() {
		assertEquals('le homine', cut.translate('the man'))
		assertEquals('la femina', cut.translate('the woman'))
		assertEquals('un grande casa', cut.translate('a big house'))
		assertEquals('bon die', cut.translate('good day'))
		assertEquals('illes anque habita in le casa', cut.translate('they also live in the house'))
		assertEquals('le casa es brun e le tecto es nigre e illo ha un jardin parve',
			cut.translate('the house is brown and the roof is black and it has a small garden'))
	}
	
	@Test
	public void testTranslateNames() {
		assertEquals('ci es Petter e Anne', cut.translate('here are Petter and Anne'))
		assertEquals('illes habita in un casa in Norvegia', cut.translate('they live in a house in Norway'))
		assertEquals('Petter e Anne ha un patre e un matre senior sr. e seniora sra. Hansen', 
			cut.translate('Petter and Anne have a father and a mother mister mr. and misses mrs. Hansen'))
		assertEquals('Anne ha un nigre catto', cut.translate('Anne has a black cat'))
		assertEquals('illo ha le nomine Mis', cut.translate('it has the name Mis'))
		assertEquals('Anne ama Mis', cut.translate('Anne loves Mis'))
		assertEquals('anque Petter ama le animal', cut.translate('also Petter loves the animal'))
		assertEquals('in le salon sede le tote familia Hansen', cut.translate('in the living room sits the entire family Hansen')) // TODO Reorder
		assertEquals('in le salon es un tabula un sofa un sedia e un comfortabile',
			cut.translate('in the living room is a table a sofa a chair and a comfychair'))
		assertEquals('sr. Hansen sede in le comfortabile e lege un magazin international de interlingua Panorama',
			cut.translate('mr. Hansen sits in the comfychair and reads a magazine international of interlingua Panorama'))
		assertEquals('sra. Hansen ascolta le radio e Anne joca con Mis', 
			cut.translate('mrs. Hansen listen to the radio and Anne plays with Mis'))
		assertEquals('Petter scribe un littera a su amico in Scotia',
			cut.translate('Petter writes a letter to his friend in Scotland'))
		assertEquals('le casa anque ha un cocina un camera a dormir un w.c. un camera pro Anne e un pro Petter',
			cut.translate('the house also has a kitchen a sleeping room a toilet one room for Anne and one for Petter'))
		//assertEquals('', cut.translate(''))
	}
	
	@Test
	public void testTranslateLection2() {
		def transMap = [
			'il es matino': 'it is morning',
			'Petter se evelia e reguarda su horologio': 'Petter woke up and looked at his clock',
			'es septe horas': "it is seven o'clock",
			'ille non pote dormir': "he can't sleep",
			'Peter ha multe libros proque ille ama leger': "Peter has many books because he likes to read",
			'le libros ha multe colores rubie verde nigre blau jalne': 
				"the books have many colors red green black blue yellow",
			'Peter jace in le lecto': 'Peter lays in the bed',
			'ille non audi que sra. Myles aperi le porta': 'he is not hearing that mrs. Myles opens the gate',
			'bon matino matre': 'good morning mother',
			'Peter se leva ab le lecto e promena a in le cocina': 'Peter gets up from the bed and walks into the kitchen',
			'ci ille vide Marilyn': 'here he sees Marilyn',
			'le catto non se move e Peter susurra': 'the cat does not move and Peter wispers',
			'Marilyn dormi tu': 'Marilyn do you sleep',
			'no Marilyn non dormi': 'no Marilyn does not sleep',
			'illo salta verso Peter': 'it jumps against Peter',
			'ha tu fame': 'are you hungry',
			'Marilyn dice miau': 'Marilyn says miau',
			'si illa ha fame': "yes she is hungry",
			'Peter da Marilyn mangiar': 'Peter gives Marilyn food',
			'nunc Ann veni':'now Ann comes',
			'da tu Marilyn mangiar Peter': 'did you give Marilyn food Peter',
			'si ille joca con le catto': 'yes he plays with the cat',
			'jentaculo matre dice': 'breakfast mother says',
			'Peter e Ann veni': 'Peter and Ann comes',
			'illes anque ha fame' : 'they also are hungry',
			'patre e matre bibe caffe': 'father and mother drink coffie',
			'que vole vos biber': 'what do you want to drink',
			'matre demanda': 'mother asks',
			'io vole con placer biber the Ann responde': 'i would like to drink tea Ann answers',
			'vole tu anque biber the Peter': 'will you also drink tea Peter',
			'no matre io vole con placer biber lacte': 'no mother i would like to drink milk',
			'e nunc tote le familia jenta': 'and now the whole family eat breakfast',
			'que es isto': 'what is this',
			//'':'',
		]
		assertTransMap(transMap)
	}
	
	@Test
	public void testTranslateLection3() {
		def transMap = [
			'hodie es mercuridi': "today it is Wednesday",
			'heri esseva martedi e deman es jovedi': 'yesterday was Tuesday and tomorrow is Thursday',
			'un septimana ha septe dies': 'a week has seven days',
			'lunedi martedi mercuridi jovedi venerdi sabbato e dominica': 'Monday Tuesday Wednesday Thursday Friday Saturday and Sunday',
			'nunc le posta veni': 'now the post comes',
			'il ha un littera pro Peter': 'there is a letter for Peter',
			'illo es ab su amico scotic': 'it is from his scottish friend',
			'Peter hasta aperir le invelope': 'Peter opens the envelope in a hurry',
			'ci es le littera': 'here is the letter',
			'car Peter': 'dear Peter',
			'multe gratias pro le littera': 'thanks a lot for the letter',
			'io non ha multe cosas a dicer te': "I don't have many things to tell you",
			'heri granpatre e granmatre nos visita': 'yesterday grandfather and grandmother visited us',
			'illes sempre dice super le dies ancian': 'they always talk about the old days',
			'illo es multo interessante!': "it's very interesting!",
			"nos anque les monstrava le citate": "we also showed them the city",
			"illo ha multe botecas": "it has many shops",
			'le tempore es bon': 'the wheather is nice',
			'le sol brilla e il es calide': "the sun is shining and it's warm",
			"ante duo dies io encontrava un danese": "two days ago I met a Dane",
			"ille parlava Interlingua e nos parlava tote le vespere":"he spoke Interlingua and we spoke the whole evening",
			"es bon que on pote usar interlingua": "it's good that one can use interlingua",
			"io spera que tu tosto scribe a me": "I hope that you will soon write to me",
		]
		assertTransMap(transMap)
	}
	
	@Test
	public void testTranslateLection4() {
		def transMap = [
			'hodie Peter recipeva un nove littera ab Scotia': "today Peter received a new letter from Scotland",
			"Andy inviava un invitation al familia Myles": "Andy sent an invitation to the Miles family",
			"ille scribeva que illes potera visitar Scotia le septimana sequente":
			 	"he wrote that they can visit Scotland next week",
			"le familia scribeva a ille que illes se gaudeva": "the family wrote to him that they enjoyed themselves",
			'nunc le familia es multo occupate': 'now the family is very busy',
			'sr. Myles va a prender le coffros': 'mr. Myles is going to take hold of the coffers',
			'pois illes comencia poner camisas, sweaters, pantalones, calceas e scarpas in illos':
			    'afterwards they begin to put shirts, sweaters, trousers, socks and shoes in them',
			'omnes es gaudiose': 'all is glad',
			'illes se gaude': 'they enjoy themselves',
			'Peter sibila e Ann e matre canta': 'Peter whisles and Ann and mother sing',
			'sr. Myles solmente surride': 'mr. Myles only smiles',
			'ille ha un idea': 'he has an idea',
//			'ille es journalista e ille va a scriber qualque articulos super le pais Scotia durante su visita illac al journal ':
//				'he is a journalist and he is going to write some articles about the country'
		]
		assertTransMap(transMap)
	}
	
	@Test
	public void testTrans5000MostUsed() {
		final transMap = [
			'le homine nata': 'the man swims', // 1 The 
			'le catto esseva grande': 'the cat was big', // 2 be
			'un homine e un femina mangia': 'a man and a woman eats', // 3 and
			'le casa de Per': 'the house of Per', // 4 of
			'io ha un libro': 'I have a book', // 5 a
			'le libros es in le casa': 'the books are in the house', // 6 in
			'esser o non esser': 'to be or not to be', // 7:to 32:or
			'io ha un catto': 'I have a cat', // 8 have
			'io veni a tu': 'I come to you', // 9 to
			'illo es un libro': 'it is a book', // 10 it
			'io es un homine': "I am a man", // 11 I
			'illes dice que ille es multo ric': 'they say that he is very rich',// 12 that
			'Tom ha un talento pro pictura moderne': "Tom has a talent for modern painting", // 13 for
			'tu ha un can': 'you have a dog', // 14 you
			'ille es grande': 'he is big', // 15 he
			'io natava con Per': 'I swam with Per', // 16 with
			'le claves esseva sur le tabula': 'the keys was on the table', // 17 on
			'isto es lo que tu debe facer': 'this is what you must do', // 18:do 34:what
			'io diceva que io esseva ci': 'I said that I was here', // 19 say
			'isto es grande': 'this is big',// 20 this
			'illes es grande': 'they are big', // 21 they
			'illa esseva a casa': 'she was at home', // 22 at
			'ma nos veniva a le partita': 'but we came to the party', // 23 but
			'post biber the, nos comenciava le discussion': 'after we had tea, we began the discussion', // 24 we
			'ille frequentemente promena con su mano in su tasca': 'he often walks with his hand in his pocket',// 25 his
			'remove le accumulator ex le detector de fumo': 'remove the battery from the smoke detector', // 26 from
			'illo es un morsura de aranea': "that's a spider bite", // 27 that
			'non mangia como un porco': "don't eat like a pig", // 28, 29 not n't
			'illa esseva attaccava per un grande serpente': 'she was attacked by a big snake', // 30:by 31:she
			'nos esseva in retardo como consequentia del paralyse de circulation': 'we were late as a result of the traffic jam', // 33:as 
			'io non va a esser capace facer illo': "I'm not going to be able to do that", // 35:go
			'Tom e Mary voleva passar le resto de lor vitas conjunctemente': 'Tom and Mary wanted to spend the rest of their lives together', // 36:their
			'illo es omnes que io pote dicer te': "that's all that I can tell you", // 37:can 43:all
			'il ha multe gente qui vole dicer a Tom': 'there are a lot of people who want to talk to Tom', // 38:who
			'le animal luctava pro partir le cavia': 'the animal struggled to get out of the cage', // 39:get
			'io non sape si ille lo sape': "I don't know if he knows it", // 40:if
			'tu non esserea capace de dicer': "you wouldn't be able to tell", // 41:would
			'illa ha cicatrices que vole durar pro le resto de su vita': 'she has scars that will last for the rest of her life', // 42:her  
			'io te amarea pro le resto de mi vita': "I'll love you for the rest of my life", // 44:my
			'que tu pensa de ille': 'what do you make of him', // 45:make
			//'': "you don't have to worry about her any more" // 46:about 
			//  47:know 48:will 49:as 50:up
		]
		assertTransMap(transMap)
		final last = transMap.values().last()
		final ina = cut.translate(last)
		println "$last --> $ina"
	}
	
	@Test
	public void testTranslateNotFound() {
		def fromText = 'notrans'
		assertEquals("*${fromText}*".toString(), cut.translate(fromText))
	}
}
